<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>毕业生信息管理系统</title>
		<meta name="description" content="这是一个 index 页面">
		<meta name="keywords" content="index">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png"
			href="<%=Const.ROOT%>assets/i/favicon.png">
		<link rel="apple-touch-icon-precomposed"
			href="<%=Const.ROOT%>assets/i/app-icon72x72@2x.png">
		<meta name="apple-mobile-web-app-title" content="Amaze UI" />
		<link rel="stylesheet"
			href="<%=Const.ROOT%>assets/css/amazeui.min.css" />
		<link rel="stylesheet" href="<%=Const.ROOT%>assets/css/admin.css">
		<link rel="stylesheet" href="<%=Const.ROOT%>assets/css/app.css">
	</head>

	<body data-type="generalComponents">

		<%@include file="top.jsp"%>

		<div class="tpl-page-container tpl-page-header-fixed">
			<!--左边start-->
			<%@include file="sidebar.jsp"%>
			<!--左边end-->
			<div class="tpl-content-wrapper">
				<!--右边内容start-->
				<ol class="am-breadcrumb">
					<li>
						<a href="<%=Const.ROOT%>manage/index.jsp" class="am-icon-home">首页</a>
					</li>
					<li class="am-active">
						毕业生档案列表
					</li>
				</ol>
				<div class="tpl-portlet-components">
					<div class="tpl-block">
						<form action="dangan_list.action" method="post" id="sform">
							<input type="hidden" name="pageBean.pageNo" value="1" id="pageNo" />

							<div class="am-g">

								<div class="am-u-sm-12 am-u-md-3">
									<div class="am-btn-toolbar">
										<div class="am-btn-group am-btn-group-xs">
											<s:if test="#session.role==2">
											<button type="button"
												class="am-btn am-btn-default am-btn-success" onclick="add()">
												<span class="am-icon-plus"></span> 新增
											</button>
											</s:if>
										</div>
									</div>
								</div>
								<div class="am-u-sm-12 am-u-md-3">
									<div class="am-input-group am-input-group-sm">
										<input type="text" name="name" class="am-form-field"
											value="<s:property value="name"/>">
										<span class="am-input-group-btn">
											<button
												class="am-btn  am-btn-default am-btn-success tpl-am-btn-success am-icon-search"
												type="submit"></button> </span>
									</div>
								</div>
							</div>
							<div class="am-g">
								<div class="am-u-sm-12">
									<table
										class="am-table am-table-striped am-table-hover table-main">
										<thead>
											<tr>
												<th class="table-id">
													编号
												</th>
												<th class="table-title">
													档案号
												</th>
												<th class="table-title">
													学生姓名
												</th>
												<th class="table-title">
													档案
												</th>
												<th class="table-set">
													操作
												</th>
											</tr>
										</thead>
										<tbody>
											<s:iterator value="list" status="st">
												<tr>
													<!--行start-->
													<td>
														<s:property value="#st.count" />
													</td>
													<td>
														<s:property value="danganno" />
													</td>
													<td>
														<s:property value="student.name" />
													</td>
													<td>
														<s:property value="docpath" />
													</td>
													<td>
														<div class="am-btn-toolbar">
															<div class="am-btn-group am-btn-group-xs">
																<s:if test="docpath!=null && docpath!=''">
																	<button
																		class="am-btn am-btn-default am-btn-xs am-hide-sm-only"
																		type="button"
																		onclick="location.href='<%=Const.ROOT%><s:property value="docpath"/>'">
																		<span class="am-icon-download"></span> 下载
																	</button>
																</s:if>

																

																<s:if test="#session.role==2">
																	<button
																		class="am-btn am-btn-default am-btn-xs am-hide-sm-only"
																		type="button"
																		onclick="toUpdate('<s:property value="id"/>')">
																		<span class="am-icon-pencil-square-o"></span> 修改
																	</button>
																	<button
																		class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
																		type="button"
																		onclick="toDelete('<s:property value="id"/>')">
																		<span class="am-icon-trash-o"></span> 删除
																	</button>
																</s:if>

															</div>
														</div>
													</td>
												</tr>
											</s:iterator>
											<!--行end-->
										</tbody>
									</table>
									<div class="am-cf">
										<div class="am-fr">
											<ul class="am-pagination tpl-pagination">
												<li>
													<a href="javascript:doPage('${pageBean.prePage }')">上一页</a>
												</li>
												<li>
													<a href="javascript:doPage('${pageBean.nextPage }')">下一页</a>
												</li>
											</ul>
										</div>
									</div>
									<hr>
								</div>
							</div>
						</form>
					</div>
					<div class="tpl-alert"></div>
				</div>
			</div>
			<!--右边内容end-->
		</div>

		<!-- 删除对话框begin -->
		<div class="am-modal am-modal-confirm" tabindex="-1" id="delete_modal">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">
					你，确定要删除这条记录吗？
				</div>
				<div class="am-modal-footer">
					<span class="am-modal-btn" data-am-modal-cancel>取消</span>
					<span class="am-modal-btn" data-am-modal-confirm>确定</span>
				</div>
			</div>
		</div>
		<!-- 删除对话框end -->
	
	<div class="am-modal am-modal-no-btn" tabindex="-1" id="add-modal">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">
					添加档案
					<a href="javascript: void(0)" class="am-close am-close-spin"
						data-am-modal-close>&times;</a>
				</div>
				<div class="am-modal-bd">
					<!-- begin -->
					<form class="am-form" name="addForm"
						action="dangan_add.action" method="post" onsubmit="return checkAdd()">
						<div class="am-g" style="margin-top: 4px;">
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
								学生
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<select id="sid" name="dangan.student.id">
								</select>
							</div>
						</div>
						<div class="am-g" style="margin-top: 4px;">
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
								档案号
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<input type="text" id="danganno" name="dangan.danganno" />
							</div>
						</div>
						<div class="am-g" style="margin-top: 4px;">
							<input type="hidden" name="orderId" id="orderId2" />
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
								档案
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<input type="file" id="fujian1" name="fujian" />
								<input type="hidden" id="docpath1" name="dangan.docpath" />
							</div>
						</div>
						<div class="am-g" style="margin-top: 4px;">
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<button type="button" onclick="updateFile1()">
									上传
								</button>
							</div>
						</div>
						<div style="margin-top: 4px;">
							<button type="submit" class="am-btn am-btn-primary am-btn-xs">
								提交保存
							</button>
							<button type="reset" class="am-btn am-btn-primary am-btn-xs">
								放弃保存
							</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	
	
		<!-- 上传就业指导书对话框begin -->
		<div class="am-modal am-modal-no-btn" tabindex="-1" id="update-modal">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">
					修改档案
					<a href="javascript: void(0)" class="am-close am-close-spin"
						data-am-modal-close>&times;</a>
				</div>
				<div class="am-modal-bd">
					<!-- begin -->
					<form class="am-form" name="updateForm"
						action="dangan_update.action" method="post"  onsubmit="return checkUpdate()">
						<input type="hidden" name="id" id="id" />
						<div class="am-g" style="margin-top: 4px;">
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
								档案号
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<input type="text" id="danganno" name="dangan.danganno" />
							</div>
						</div>
						<div class="am-g" style="margin-top: 4px;">
							<input type="hidden" name="orderId" id="orderId2" />
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
								档案
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<input type="file" id="fujian2" name="fujian" />
								<input type="hidden" id="docpath2" name="dangan.docpath" />
							</div>
						</div>
						<div class="am-g" style="margin-top: 4px;">
							<div class="am-u-sm-3 am-u-md-3 am-text-right">
							</div>
							<div class="am-u-sm-9 am-u-md-9 am-u-end col-end">
								<button type="button" onclick="updateFile2()">
									上传
								</button>
							</div>
						</div>
						<div style="margin-top: 4px;">
							<button type="submit" class="am-btn am-btn-primary am-btn-xs">
								提交保存
							</button>
							<button type="reset" class="am-btn am-btn-primary am-btn-xs">
								放弃保存
							</button>
						</div>
					</form>
				</div>
			</div>
		</div>
		<!-- 修改对话框end -->
		<script src="<%=Const.ROOT%>assets/js/jquery.min.js"></script>
		<script src="<%=Const.ROOT%>assets/js/amazeui.min.js"></script>
		<script src="<%=Const.ROOT%>assets/js/app.js"></script>
		<script src="<%=Const.ROOT%>js/ajaxfileupload.js"></script>

		<script>
		function add() {
			$("#add-modal").modal({
				width: 500,
				height: 280
			});
		}
		 $(function(){
			  loadOptions("sid","-1");
		  });
			function loadOptions(domid,tid){
				$.getJSON("<%=Const.ROOT%>student_listJson.action",function(data){
						$("#"+domid).html("<option value='-1'>请选择学生</option>");
						$.each(data,function(index,item){
							if(item.id==tid){
								$("#"+domid).append("<option value='"+item.id+"' selected>"+item.name+"</option>");
							}else{
								$("#"+domid).append("<option value='"+item.id+"'>"+item.name+"</option>");
							}
						});
				});
			}


			function checkAdd(){
				if($("#add-modal #sid").val()=="-1"){
			  		alert("请选择学生");
			  		return false;
			  	}
			  	if($("#add-modal #danganno").val()==""){
			  		alert("请输入档案号");
			  		return false;
			  	}
			  	if($("#add-modal #docpath1").val()==""){
			  		alert("请选择档案");
			  		return false;
			  	}
			  	return true;
			}
			function checkUpdate(){
				
			  	if($("#update-modal #danganno").val()==""){
			  		alert("请输入档案号");
			  		return false;
			  	}
			  	if($("#update-modal #docpath2").val()==""){
			  		alert("请选择档案");
			  		return false;
			  	}
			  	return true;
			}
			

			function toDelete(id) {
				$("#delete_modal").modal({
					relatedTarget: this,
					onConfirm: function(options) {
						//执行删除
						location.href = "dangan_delete.action?id=" + id;
					},
					onCancel: function() {
					}
				});
			}

			//上传文件
			  function updateFile1(){
				  if($("#fujian1").val()==""){
					  alert("请先选择文件!");
				  }else{
				  $.ajaxFileUpload
		          (
		              {
		                  url: '<%=Const.ROOT%>upload.action', //用于文件上传的服务器端请求地址
		                  secureuri: false, //是否需要安全协议，一般设置为false
		                  fileElementId: 'fujian1', //文件上传域的ID
		                  success: function (data, status)  //服务器成功响应处理函数
		                  {        	
		                	  $("#docpath1").val($(data).find("body").text());
		                	  alert("上传成功，请点击保存！");
		                  },
		                  error: function (data, status, e)//服务器响应失败处理函数
		                  {
		                      alert("上传失败!");
		                  }
		              }
		          );
				  }
		          return false;
		      }

			  function updateFile2(){
				  if($("#fujian2").val()==""){
					  alert("请先选择文件!");
				  }else{
				  $.ajaxFileUpload
		          (
		              {
		                  url: '<%=Const.ROOT%>upload.action', //用于文件上传的服务器端请求地址
		                  secureuri: false, //是否需要安全协议，一般设置为false
		                  fileElementId: 'fujian2', //文件上传域的ID
		                  success: function (data, status)  //服务器成功响应处理函数
		                  {        	
		                	  $("#docpath2").val($(data).find("body").text());
		                	  alert("上传成功，请点击保存！");
		                  },
		                  error: function (data, status, e)//服务器响应失败处理函数
		                  {
		                      alert("上传失败!");
		                  }
		              }
		          );
				  }
		          return false;
		      }
			
			function toUpdate(id){
				$.getJSON("dangan_detail.action",{"id":id},function(data){
					$("#update-modal #id").val(id);
					$("#update-modal #danganno").val(data.danganno);
					$("#update-modal #docpath2").val(data.docpath);
					$("#update-modal").modal({width:500,height:250});
				})
			}
			function doPage(pageNo){
				$("#pageNo").val(pageNo);
				$("#sform").submit();
			}
			
</script>
	</body>

</html>